<?php
function includeModelFile(){
	$arrayfile=getfileName(dirname(dirname(dirname(__FILE__))).'/model');
	foreach($arrayfile as $num=>$filename){
		$file=stringToExec(dirname(__FILE__).'/../../model/'.$filename);
		$file='include_once "'.dirname(__FILE__).'/model.class.php";  '.$file;
		$file=str_replace("{"," extends Model{",$file,$num=1);
		$file=str_replace("}",constructFindBy($filename).'}',$file,$num=1);
		echo $file;
		eval($file);
	}
}

//构造所有model参数的findby函数
function constructFindBy($file){
	$result='';
	$fileContent=stringToExec(dirname(__FILE__).'/../../model/'.$file); 
	$arrayname=explode("{",$fileContent);
	$arrayname1=explode(" ",$arrayname[0]);
	$className=trim($arrayname1[1]);
	$num=0;
	$fileContenttemp='class '.$className.'temp{'.$arrayname[1];
	eval($fileContenttemp);
	$array_var=get_class_vars($className."temp");
	foreach($array_var as $name => $type) {
		if(!in_array($name,array('ArrayType','db'))){
			if(in_array($type,array('bool','float','double','real','int','string','date','year'))){
				$evalstring=' function __findBy'.ucfirst($name).'($parameter){';
				switch($type){
					case "bool":	
					case "float":
					case "double":
					case "real":
					case "int":$evalstring.='$this->db->select(get_class($this),"`id`",\''.$name.'=\'.$parameter);';break;
					case "string":$evalstring.='$this->db->select(get_class($this),"`id`",\'`'.$name.'` LIKE \\\'%\'.$parameter.\'%\\\'\');';break;
					case "date":$evalstring.='$this->db->select(get_class($this),"`id`",$parameter);';break;
				}
				$evalstring.='if($this->db->__get("resultNumber")==0)return;
								$result=array();
								foreach($this->db->result as $key => $arrayvalue){
									array_push($result,intval($arrayvalue[\'id\']));
								}
								return $result;}';
				$result.=$evalstring;
			}
		}		
	}

	return $result;
}